var userAgent = navigator.userAgent.toLowerCase();
var isIE = window.ActiveXObject && userAgent.indexOf('msie') != -1 && userAgent.substr(userAgent.indexOf('msie') + 5, 3);
function $$(a) {
    return typeof a == "string" ? document.getElementById(a) : a
}
function html(a) {
    return a.replace(/\\/g, '').replace(/\&amp;/g, '&').replace(/\&#039;/g, "'").replace(/\&quot;/g, '"').replace(/\&lt;/g, '<').replace(/\&gt;/g, '>')
}
function flashTitle() {
    clearInterval(tttt);
    flashtitle_step = 1;
    tttt = setInterval(function () {
        if (flashtitle_step == 1) {
            document.title = '【新消息】' + pagetitle;
            flashtitle_step = 2
        } else {
            document.title = '【　　　】' + pagetitle;
            flashtitle_step = 1
        }
    }, 200)
}
function stopFlashTitle() {
    if (flashtitle_step != 0) {
        flashtitle_step = 0;
        clearInterval(tttt);
        document.title = pagetitle
    }
}
function getLocalTime() {
    var c = new Date();

    function addZeros(a, b) {
        var i;
        a = "" + a;
        if (a.length < b) {
            for (i = 0; i < (b - a.length); i++)a = "0" + a
        }
        return a
    }

    return addZeros(c.getHours(), 2) + ':' + addZeros(c.getMinutes(), 2) + ':' + addZeros(c.getSeconds(), 2)
}
function showInfo(a, b, c, d, e) {
    var f = d ? d * 1000 : 0;
    if (e) {
        var b = "<font color=#33CC00>" + (b ? b : "系统信息") + "</font>";
        var g = "<font color=blue>" + a + "</font>"
    } else {
        var b = "<font color=red>" + (b ? b : "系统信息") + "</font>";
        var g = "<font color=#FF9900>" + a + "</font>"
    }
    easyDialog.open({
        container: {
            header: b, content: g, yesFn: function () {
            }, yesText: '确定'
        }, autoClose: f, callback: c
    });
    $("#easyDialogYesBtn").focus()
}
function showDialog(a, b, c, d) {
    var e = d ? d * 1000 : 0;
    easyDialog.open({
        container: {
            header: "<font color=red>" + (b ? b : "系统信息") + "</font>",
            content: "<font color=#FF9900>" + a + "</font>",
            yesFn: c,
            yesText: '确定',
            noFn: true,
            noText: '取消'
        }, autoClose: e
    });
    $("#easyDialogYesBtn").focus()
}
(function (a) {
    a.fn.Jdropdown = function (b, c) {
        if (this.length) {
            "function" == typeof b && (c = b, b = {});
            var d = a.extend({
                event: "mouseover",
                current: "hover",
                delay: 0
            }, b || {}), e = "mouseover" == d.event ? "mouseout" : "mouseleave";
            a.each(this, function () {
                var b = null, f = null, g = !1;
                a(this).bind(d.event, function () {
                    if (g)clearTimeout(f); else {
                        var e = a(this);
                        b = setTimeout(function () {
                            e.addClass(d.current), g = !0, c && c(e)
                        }, d.delay)
                    }
                }).bind(e, function () {
                    if (g) {
                        var c = a(this);
                        f = setTimeout(function () {
                            c.removeClass(d.current), g = !1
                        }, 0)
                    } else clearTimeout(b)
                })
            })
        }
    }
})(jQuery);
function createWin(a, b, c, d) {
    var x = x_win_content.replace('888888', c);
    myWin88.Create(a, b, x, d)
}
function openWin(a) {
    myWin88.Show(a)
}
function closeWin(a) {
    myWin88.Min(a)
}
function WeLiveWin() {
    this.Create = function (a, b, c, d) {
        var f = document.createElement("DIV");
        f.setAttribute("id", "win" + a);
        f.className = "x-win";
        f.onmouseup = function () {
            openWin(a)
        };
        f.style.zIndex = zIndex;
        document.body.appendChild(f);
        var g = document.createElement("DIV");
        var h = document.createElement("DIV");
        var j = document.createElement("DIV");
        g.className = "x-title";
        h.className = "x-body";
        j.className = "x-bottom";
        f.appendChild(g);
        f.appendChild(h);
        f.appendChild(j);
        var k, g_tools, wintag = [g, g, g, h, h, h, j, j, j];
        for (var i = 0; i < 9; i++) {
            var m = document.createElement("DIV");
            wintag[i].appendChild(m);
            if (i == 0) {
                m.className = "x-titleleft"
            } else if (i == 1) {
                m.className = "x-titlemid"
            } else if (i == 2) {
                m.className = "x-titleright"
            } else if (i == 3) {
                m.className = "x-bodyleft"
            } else if (i == 4) {
                m.className = "x-bodymid";
                k = m
            } else if (i == 5) {
                m.className = "x-bodyright"
            } else if (i == 6) {
                m.className = "x-bottomleft"
            } else if (i == 7) {
                m.className = "x-bottomid"
            } else if (i == 8) {
                m.className = "x-bottomright"
            }
            if (i != 4 && i != 2)m.onmousedown = function (e) {
                myWin88.Move(f, e)
            }
        }
        g.childNodes[1].innerHTML = '<div class="x-user">' + b + '&nbsp;</div><div id="min168" class="x-min" onclick="closeWin(' + a + ');" title="最小化" onMouseover="this.className=\'x-min2\';" onMouseout="this.className=\'x-min\';"></div>';
        h.childNodes[1].innerHTML = c;
        var l = guest.length == 1 ? parseInt(($(window).width() - 780) / 2) : parseInt(Math.random() * ($(window).width() - 780));
        var t = guest.length == 1 ? parseInt(($(window).height() - 500) / 2) : parseInt(Math.random() * ($(window).height() - 500));
        this.Move_e(f, l, t);
        $(k).children(".g_history").welivebar();
        $(k).children(".g_bott").children(".g_msg").keyup(function (e) {
            if (e.keyCode == 13)guest_send()
        });
        g_tools = $(k).children(".g_tools");
        g_tools.children(".t_smilies").tipTip({
            content: $(".smilies_div").html().replace(/towhere/ig, a),
            keepAlive: true,
            maxWidth: "354px",
            defaultPosition: "top",
            edgeOffset: 0,
            delay: 300,
            parent: true,
            hoverClass: "hover"
        });
        g_tools.children(".t_phrase").tipTip({
            content: (d == 1 ? $(".phrases_div").html().replace(/towhere/ig, a) : $(".phrasesen_div").html().replace(/towhere/ig, a)),
            keepAlive: true,
            maxWidth: "354px",
            defaultPosition: "top",
            edgeOffset: 0,
            delay: 400,
            parent: true,
            hoverClass: "hover"
        });
        g_tools.children(".t_kickout").tipTip({
            content: '<input class="save" type="submit" value="确定踢出" onclick="guest_kickout();return false;">',
            activation: "click",
            keepAlive: true,
            maxWidth: "354px",
            defaultPosition: "top",
            edgeOffset: 4,
            delay: 0,
            hoverClass: "hover"
        });
        g_tools.children(".t_note").tipTip({
            content: '商业lyd功能 ...',
            activation: "click",
            keepAlive: true,
            maxWidth: "354px",
            defaultPosition: "top",
            edgeOffset: 4,
            delay: 0,
            hoverClass: "hover"
        });
        g_tools.children(".t_transfer").tipTip({
            content: '<div class="s_transfer">&nbsp;</div>',
            enter: function () {
                get_supporters()
            },
            activation: "click",
            keepAlive: true,
            maxWidth: "354px",
            defaultPosition: "top",
            edgeOffset: 0,
            delay: 0,
            parent: true,
            hoverClass: "hover"
        })
    };
    this.Show = function (a) {
        welive.where = 1;
        s_title.addClass("off");
        var o = $('#win' + a);
        if (a != CurrentId) {
            o.css({visibility: 'visible', 'z-index': ++zIndex});
            g_online.find("#g" + a + ">b").html(0).hide();
            $('#win' + CurrentId).find('.x-user').removeClass("x-now");
            CurrentId = a;
            o.find('.g_msg').focus();
            o.find('.x-user').addClass("x-now")
        } else if (!o.find('.x-user').hasClass("x-now")) {
            o.find('.g_msg').focus();
            o.find('.x-user').addClass("x-now")
        }
    };
    this.Min = function (a) {
        CurrentId = 0;
        if ($.inArray(a, offline) > -1) {
            guest_delete(a)
        } else {
            $('#win' + a).css('visibility', 'hidden')
        }
        showLast()
    };
    this.Move = function (o, a) {
        if (!o)return;
        a = a ? a : window.event;
        var b = a.srcElement ? a.srcElement : a.target;
        if (b.id == "min168")return;
        var w = o.offsetWidth;
        var h = o.offsetHeight;
        var l = o.offsetLeft;
        var t = o.offsetTop;
        var c = document.createElement("DIV");
        document.body.appendChild(c);
        c.className = "x-drag";
        c.style.cssText = "top:" + t + "px;left:" + l + "px;";
        this.Move_r(c, o, a)
    };
    this.Move_r = function (o, f, g) {
        o.style.zIndex = zIndex + 1;
        g = g ? g : window.event;
        var h = g.clientX - o.offsetLeft;
        var i = g.clientY - o.offsetTop;
        if (!window.captureEvents) {
            o.setCapture()
        } else {
            window.captureEvents(Event.MOUSEMOVE | Event.MOUSEUP)
        }
        document.onmousemove = function (e) {
            if (!o)return;
            window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
            e = e ? e : window.event;
            var a = e.clientX - h;
            var b = e.clientY - i;
            var c = $(window).width() - o.offsetWidth - 2;
            var d = $(window).height() - o.offsetHeight - 2;
            if (a <= 1) {
                o.style.left = "1px"
            } else if (a >= c) {
                o.style.left = c + "px"
            } else {
                o.style.left = a + "px"
            }
            if (b <= 1) {
                o.style.top = "1px"
            } else if (b >= d) {
                o.style.top = d + "px"
            } else {
                o.style.top = b + "px"
            }
        };
        document.onmouseup = function () {
            if (!o)return;
            if (!window.captureEvents) {
                o.releaseCapture()
            } else {
                window.releaseEvents(Event.MOUSEMOVE | Event.MOUSEUP)
            }
            myWin88.Move_e(f, o.offsetLeft, o.offsetTop);
            var a = f.id.replace(/win/ig, "");
            if (a != CurrentId) {
                openWin(a)
            } else {
                $(f).focus().find('.g_msg').focus()
            }
            document.body.removeChild(o);
            o = null
        }
    };
    this.Move_e = function (o, l, t) {
        if (!o)return;
        o.style.left = l + "px";
        o.style.top = t + "px"
    }
}
function showLast() {
    var o, oz, xId = 0, xIndex = 0;
    $.each(guest, function (i, a) {
        o = $('#win' + a);
        if (o.length && o.css("visibility") == 'visible') {
            oz = parseInt(o.css("z-index"));
            if (oz > xIndex) {
                xId = a;
                xIndex = oz
            }
        }
    });
    if (xId) {
        openWin(xId)
    } else {
        s_msg.focus()
    }
}
function showNext(b) {
    var o, oz, xId = 0, xIndex = 1000000000, xxx = b ? "hidden" : "visible";
    $.each(guest, function (i, a) {
        o = $('#win' + a);
        if (o.length && o.css("visibility") == xxx) {
            oz = parseInt(o.css("z-index"));
            if (oz < xIndex) {
                xId = a;
                xIndex = oz
            }
        }
    });
    if (xId) {
        openWin(xId)
    } else if (CurrentId) {
        openWin(CurrentId)
    }
}
var WebSocket = window.WebSocket || window.MozWebSocket;
//if (!WebSocket) {
//    var ws_obj = {};
//    var ws_ready = false;
//    $(window).load(function () {
//        ws_ready = true
//    });
//    $(function () {
//        $.ajax({url: SYSDIR + 'public/jquery.swfobject.js', dataType: 'script', async: false, cache: true});
//        window.WebSocket = function (a) {
//            a = a.match(/wss{0,1}\:\/\/([0-9a-z_.-]+)(?:\:(\d+)){0,1}/i);
//            this.host = a[1];
//            this.port = a[2] || 843;
//            this.onopen = function () {
//            };
//            this.onclose = function () {
//            };
//            this.onmessage = function () {
//            };
//            this.onerror = function () {
//            };
//            this.ready = function (b) {
//                return true
//            };
//            this.send = function (b) {
//                return ws_obj.call.Send(b)
//            };
//            this.close = function () {
//                return ws_obj.call.Close()
//            };
//            this.ping = function () {
//                return ws_obj.call.Ping()
//            };
//            this.connect = function () {
//                ws_obj.call = $('#flash_websocket')[0];
//                ws_obj.call.Connect(this.host, this.port)
//            };
//            this.onmessage_escape = function (d) {
//                this.onmessage({data: unescape(d)})
//            };
//            if ($('#websocket1212').size()) {
//                this.connect()
//            } else {
//                var c = $('<div></div>').attr({id: 'websocket1212'}).css({position: 'absolute', top: -999, left: -999});
//                c.flash({
//                    swf: SYSDIR + 'public/websocket.swf?r=' + Math.random(),
//                    wmode: "window",
//                    scale: "showall",
//                    allowFullscreen: true,
//                    allowScriptAccess: 'always',
//                    id: 'flash_websocket',
//                    width: 1,
//                    height: 1,
//                    flashvars: {call: 'ws_obj._this'}
//                });
//                $('body').append(c)
//            }
//            ws_obj._this = this
//        }
//    })
//}
function format_output(b) {
    b = b.replace(/((href=\"|\')?(((https?|ftp):\/\/)|www\.)([\w\-]+\.)+[\w\.\/=\?%\-&~\':+!#;]*)/ig, function (a) {
        return getURL(a)
    });
    b = b.replace(/([\-\.\w]+@[\.\-\w]+(\.\w+)+)/ig, '<a href="mailto:$1" target="_blank">$1</a>');
    b = b.replace(/\[:(\d*):\]/g, '<img src="' + SYSDIR + 'public/smilies/$1.png">').replace(/\\/g, '');
    return b
}
function getURL(a, b) {
    if (a.substr(0, 5).toLowerCase() == 'href=')return a;
    if (!b)b = 60;
    var c = '<a href="' + (a.substr(0, 4).toLowerCase() == 'www.' ? 'http://' + a : a) + '" target="_blank" title="' + a + '">';
    if (a.length > b) {
        a = a.substr(0, 30) + ' ... ' + a.substr(a.length - 18)
    }
    c += a + '</a>';
    return c
}
function insertSmilie(a, b) {
    a = '[:' + a + ':]';
    if (b) {
        openWin(b);
        var c = $("#win" + b).find(".g_msg")[0];
        if (!c)return
    } else {
        var c = s_msg[0]
    }
    var d = document.selection;
    c.focus();
    if (typeof c.selectionStart != 'undefined') {
        var e = c.selectionStart + 0;
        c.value = c.value.substr(0, c.selectionStart) + a + c.value.substr(c.selectionEnd)
    } else if (d && d.createRange) {
        var f = d.createRange();
        f.text = a;
        f.moveStart('character', -a.length)
    } else {
        c.value += a
    }
}
function insertPhrase(a, b) {
    code = $(a).children("b").html();
    openWin(b);
    var c = $("#win" + b).find(".g_msg")[0];
    if (!c)return;
    var d = document.selection;
    c.focus();
    if (typeof c.selectionStart != 'undefined') {
        var e = c.selectionStart + 0;
        c.value = c.value.substr(0, c.selectionStart) + code + c.value.substr(c.selectionEnd)
    } else if (d && d.createRange) {
        var f = d.createRange();
        f.text = code;
        f.moveStart('character', -code.length)
    } else {
        c.value += code
    }
    $("#tiptip_holder").hide()
}
function welive_link() {
    welive.ws = new WebSocket('ws://' + WS_HOST + ':' + WS_PORT + '/');
    welive.ws.onopen = function (e) {
        setTimeout(welive_verify, 100)
        console.log('admin端握手成功下面紧紧打印打开链接成功的回调e_json'+ e);
        console.log(e);
    };
    welive.ws.onclose = function (e) {
        welive_close()
        console.log('关闭链接'+e);
    };
    welive.ws.onmessage = function (a) {
        welive_parseOut(a.data);
        console.log('admin响应数据'+a.data + '跟着admin解析后的a.data');
        console.log(window.JSON.parse(a.data));
    }
}
function TitleSound(x) {
    if (welive.flashTitle && x) {
        flashTitle();
        if (welive.sound)sounder.html(welive.sound1);
        welive.flashTitle = 0
    } else if (welive.flashTitle) {
        if (welive.sound)sounder.html(welive.sound2);
        welive.flashTitle = 0
    }
}
function welive_clear() {
    var a = s_history.children("div");
    var b = a.length;
    if (b >= 100) {
        a.slice(0, b - 50).remove();
        s_hwrap.welivebar_update('bottom')
    }
}
function admins_update(n) {
    var x = parseInt(s_admins.html());
    x = x + n;
    if (x < 0)x = 0;
    s_admins.html(x)
}
function welive_parseOut(b) {
    var c = 0, d = false, type = 0, b = $.parseJSON(b);
    switch (b.x) {
        case 4:
            welive_runtime(b.g, b.i);
            return;
            break;
        case 2:
            switch (b.a) {
                case 1:
                    d = '<div class=i><b></b>' + b.n + ' 上线了</div>';
                    s_online.append('<li id="index_' + b.ix + '" title="' + b.p + '"><div><img src="' + SYSDIR + 'avatar/' + b.av + '" title="服务中..."></div><i' + (b.t == 1 ? ' class=a' : '') + '>' + b.n + '</i></li>');
                    admins_update(1);
                    break;
                case 2:
                    d = '<div class=i><b></b>' + b.i + ' 已离线</div>';
                    s_online.find("#index_" + b.ix).remove();
                    admins_update(-1);
                    break;
                case 3:
                    var a = s_online.find("#index_" + b.ix);
                    d = '<div class=i><b></b>' + a.children("i").html() + ' 已挂起</div>';
                    a.children("div").append('<b></b>');
                    a.children("div").children("img").attr('title', '已挂起');
                    if (b.ix == welive.index) {
                        $(".set_busy").hide();
                        $(".set_serving").show()
                    }
                    break;
                case 4:
                    var a = s_online.find("#index_" + b.ix);
                    d = '<div class=i><b></b>' + a.children("i").html() + ' 解除挂起</div>';
                    a.children("div").children("b").remove();
                    a.children("div").children("img").attr('title', '服务中...');
                    if (b.ix == welive.index) {
                        $(".set_serving").hide();
                        $(".set_busy").show()
                    }
                    break;
                case 8:
                    d = '<div class=i><b></b>服务器连接成功!</div>';
                    welive.index = b.ix;
                    s_hwrap.removeClass('loading3');
                    var f = 0, status;
                    $.each(b.al, function (n, a) {
                        f += 1;
                        if (a.b == 1) {
                            status = '已挂起"><b></b'
                        } else {
                            status = '服务中..."'
                        }
                        if (a.id == admin.id)admin.aix = a.ix;
                        s_online.append('<li id="index_' + a.ix + '" title="' + a.p + '"><div><img src="' + SYSDIR + 'avatar/' + a.av + '" title="' + status + '></div><i' + (a.t == 1 ? ' class=a' : '') + '>' + a.n + '</i></li>')
                    });
                    admins_update(f);
                    if (guest.length) {
                        $.each(guest, function (i, a) {
                            if ($.inArray(a, b.gl) < 0 && $.inArray(a, offline) < 0) {
                                offline.push(a);
                                guest_output('客人已离线!', a, 4);
                                g_online.find('#g' + a).addClass("offline");
                                var o = $("#win" + a).find(".x-user");
                                o.html(o.html() + ' -- 已离线')
                            }
                        })
                    } else {
                        $.each(b.gl, function (i, a) {
                            guest_create(a.g, a.n, a.l, 1)
                        })
                    }
                    $(".set_busy").click(function (e) {
                        showDialog('确定挂起吗?<br>注: 挂起后, 将不再接受新客人加入.<br>但是, 转接过来的客人仍会加入.', '', function () {
                            welive_send('x=2&a=3')
                        });
                        e.preventDefault()
                    });
                    $(".set_serving").click(function (e) {
                        welive_send('x=2&a=4');
                        e.preventDefault()
                    });
                    $(".reset_socket").click(function (e) {
                        showDialog('确定重启Socket通讯服务吗?<br>注: 所有连接将中断! 无特殊原因, 请勿重启.', '', function () {
                            welive_send('x=2&a=9');
                            setTimeout(function () {
                                $.ajax({
                                    url: './index.php?c=opensocket&a=ajax',
                                    dataType: 'json',
                                    async: true,
                                    cache: false
                                })
                            }, 2000)
                        });
                        e.preventDefault()
                    });
                    setInterval(welive_clear, 1000 * 1200);
                    break
            }
            break;
        case 5:
            c = b.g;
            d = b.i;
            if (b.a == 1) {
                type = 1
            } else {
                welive.flashTitle = 1;
                type = 2
            }
            break;
        case 6:
            switch (b.a) {
                case 8:
                    guest_create(b.g, b.n, b.l, b.re);
                    break;
                case 3:
                    c = b.g;
                    type = 4;
                    d = '客人已离线!';
                    offline.push(c);
                    g_online.find('#g' + c).addClass("offline");
                    var o = $("#win" + c).find(".x-user");
                    o.html(o.html() + ' -- 已离线');
                    break;
                case 11:
                    if (b.i == 1) {
                        c = b.g;
                        type = 3;
                        d = '客人转接成功.';
                        offline.push(c);
                        g_online.find('#g' + c).addClass("offline");
                        var o = $("#win" + c).find(".x-user");
                        o.html(o.html() + ' -- 已转接')
                    } else {
                        c = b.g;
                        type = 4;
                        d = '客人转接失败!'
                    }
                    break
            }
            break
    }
    welive_output(d, c, type)
}
function guest_create(a, n, b, c) {
    if (!a)return;
    welive.flashTitle = 1;
    var d, i = $.inArray(a, offline);
    if (i > -1) {
        d = '客人重新上线了!';
        offline.splice(i, 1);
        g_online.find('#g' + a).removeClass("offline");
        var o = $("#win" + a).find(".x-user");
        o.html(o.html().replace(' -- 已离线', '').replace(' -- 已转接', ''))
    } else if ($.inArray(a, guest) < 0) {
        guest.push(a);
        if (n == '')n = ((b == 1) ? 'vip会员 ' : ' Guest ') + a;
        g_online.prepend('<div id="g' + a + '" onclick="openWin(' + a + ');" class="g" title="' + n + '"><i>' + n + '</i><b>0</b></div>');
        var e = '';
        if (c === 1) {
            d = '重新上线的通知已发送!'
        } else {
            d = '客人上线, 问候语已发送!'
        }
        createWin(a, n, e, b)
    } else {
        welive.flashTitle = 0;
        return
    }
    guest_output(d, a, 3)
}
function guest_update(a) {
    var o = g_online.find("#g" + a + ">b");
    var x = parseInt(o.html());
    x = x + 1;
    o.html(x).show()
}
function guest_delete(a) {
    $('#win' + a).remove();
    g_online.find('#g' + a).remove();
    guest.splice($.inArray(a, guest), 1);
    offline.splice($.inArray(a, offline), 1)
}
function guest_output(d, a, b) {
    if (!d || !a || !b)return;
    TitleSound(1);
    var o = $("#win" + a).find(".g_history");
    o.find(".overview>div.updating").remove();
    switch (b) {
        case 1:
            d = '<div class="msg r"><b></b><div class="b"><div class="i">' + format_output(d) + '</div></div><i>' + getLocalTime() + '</i></div>';
            break;
        case 2:
            d = '<div class="msg l"><b></b><div class="b"><div class="i">' + format_output(d) + '</div></div><i>' + getLocalTime() + '</i></div>';
            break;
        case 3:
            d = '<div class="msg s"><div class="b"><div class="ico"></div><div class="i">' + d + '</div></div></div>';
            break;
        case 4:
            d = '<div class="msg e"><div class="b"><div class="ico"></div><div class="i">' + d + '</div></div></div>';
            break
    }
    o.find(".overview").append(d);
    o.welivebar_update('bottom');
    if (!CurrentId || !welive.where) {
        openWin(a)
    } else {
        if (CurrentId != a)guest_update(a)
    }
}
function welive_output(d, a, b) {
    if (a) {
        guest_output(d, a, b)
    } else {
        if (d === false)return;
        TitleSound();
        s_history.append(d);
        s_hwrap.welivebar_update('bottom')
    }
}
function welive_verify() {
    welive.status = 1;
    console.log('当打开open开始,执行wilive_verify()发送的数据是:::x=2&a=8&s=' + admin.sid + '&ag=' + admin.agent + '&id=' + admin.id);
    welive_send('x=2&a=8&s=' + admin.sid + '&ag=' + admin.agent + '&id=' + admin.id);
    $(".set_serving").hide();
    $(".set_busy").show()
}
function welive_close() {
    if (welive.status) {
        $.ajax({url: './index.php?c=opensocket&a=ajax', dataType: 'json', async: true, cache: false});
        s_online.html("");
        s_admins.html(0)
    }
    welive.status = 0;
    $("#websocket1212").remove();
    welive_output('<div class="i"><b></b>连接失败, 3秒后自动重试 ...</div>');
    welive.ttt = setTimeout(welive_link, 3000)
}
function welive_send(d) {
    s_send.addClass('loading2');
    if (welive.status) {
        console.log( '----' + d +'----这里是admin和admin间发送的数据,马上开始就是等待响应');
        welive.ws.send(d);
        s_msg.val('')
    } else {
        welive_output('<div class=i><b></b>服务器连接中, 请等待 ...</div>')
    }
    s_msg.focus();
    s_send.removeClass('loading2')
}
function guest_send() {
    if (!CurrentId || $.inArray(CurrentId, offline) > -1)return;
    var o = $('#win' + CurrentId).find('.g_msg');
    var a = $.trim(o.val());
    if (welive.status && a) {
        //alert(1)
        a = a.replace(/&/g, "||4||");
        console.log( '----' + 'x=5&g=' + CurrentId + '&i=' + a +'----这里是admin和会员间发送的数据,马上开始就是等待响应');
        welive.ws.send('x=5&g=' + CurrentId + '&i=' + a);
        o.val('')
    }
    o.focus()
}
function guest_kickout() {
    if ($.inArray(CurrentId, offline) < 0)welive.ws.send('x=6&a=6&g=' + CurrentId);
    guest_delete(CurrentId);
    CurrentId = 0;
    $("#tiptip_holder").hide();
    showNext()
}
function guest_banned(a) {
    if ($.inArray(CurrentId, offline) > -1)return;
    welive.ws.send('x=6&a=7&g=' + CurrentId);
    guest_output('客人已被禁言, 但你仍然可以对其发言!', CurrentId, 4);
    $(a).parent().children(".t_unban").show();
    $(a).hide()
}
function guest_unban(a) {
    if ($.inArray(CurrentId, offline) > -1)return;
    welive.ws.send('x=6&a=10&g=' + CurrentId);
    guest_output('客人禁言状态已解除.', CurrentId, 3);
    $(a).parent().children(".t_banned").show();
    $(a).hide()
}
function get_supporters() {
    if ($.inArray(CurrentId, offline) > -1) {
        $('.s_transfer').html('客人已离线, 无法转接!');
        return
    }
    var b = 0;
    $('.s_transfer').html(s_online.html()).children('li').each(function () {
        var a = $(this).attr('id').replace('index_', '');
        if (admin.aix == a) {
            $(this).remove();
            return
        }
        b += 1;
        $(this).click(function () {
            if ($.inArray(CurrentId, offline) > -1) {
                guest_output('客人已离线, 无法转接!', CurrentId, 4);
                return
            }
            welive.ws.send('x=6&a=11&g=' + CurrentId + '&aix=' + a);
            $("#tiptip_holder").hide()
        })
    });
    if (!b)$('.s_transfer').html('暂无其它客服可转接!')
}
function welive_runtime(a, b) {
    if (!a || !b)return;
    b = format_output(b) + ' <img src="' + SYSDIR + 'public/img/writting.gif">';
    var o = $("#win" + a).find(".g_history");
    var c = o.find(".overview>div.updating");
    if (c.length) {
        c.find(".i").html(b)
    } else {
        b = '<div class="msg updating"><b></b><div class="b"><div class="i">' + b + '</div></div></div>';
        o.find(".overview").append(b)
    }
    o.welivebar_update('bottom')
}
function welive_init() {
    guest = new Array();
    offline = new Array();
    g_online = $("#g");
    s_chat = $("#s_chat");
    s_msg = s_chat.find(".s_msg");
    s_send = s_chat.find(".s_send");
    s_admins = s_chat.find(".s_admins");
    s_title = s_chat.find(".s_title").children(".l");
    s_hwrap = s_chat.find("#s_hwrap");
    s_owrap = s_chat.find("#s_owrap");
    s_history = s_hwrap.find(".overview");
    s_online = s_owrap.find(".overview");
    sounder = $("#wl_sounder");
    welive_link();
    myWin88 = new WeLiveWin();
    var b = s_hwrap.find(".viewport"), s_onlineViewport = s_owrap.find(".viewport"), xHeight = $(window).height() - 88;
    g_online.height(xHeight);
    s_chat.height(xHeight);
    b.height(xHeight - 78);
    s_onlineViewport.height(xHeight - 74);
    s_hwrap.welivebar();
    s_owrap.welivebar();
    $(window).resize(function () {
        var a = $(window).height() - 88;
        g_online.height(a);
        s_chat.height(a);
        b.height(a - 78);
        s_onlineViewport.height(a - 74);
        s_hwrap.welivebar_update('bottom');
        s_owrap.welivebar_update()
    });
    s_msg.keyup(function (e) {
        if (e.keyCode == 13)s_send.trigger("click")
    }).focus(function () {
        s_title.removeClass("off");
        welive.where = 0;
        if (CurrentId)$('#win' + CurrentId).find('.x-user').removeClass("x-now")
    });
    s_send.click(function (e) {
        var a = $.trim(s_msg.val());
        if (a) {
            welive_output('<div class=i><b></b>抱歉, 时间有限,等待二期开发....</div>')
        } else {
            s_msg.focus()
        }
        e.preventDefault()
    });
    $("#wl_ring").click(function (e) {
        if (welive.sound) {
            welive.sound = 0;
            $(this).addClass("s_ringoff").removeClass("s_ring")
        } else {
            welive.sound = 1;
            $(this).addClass("s_ring").removeClass("s_ringoff")
        }
        s_msg.focus();
        e.preventDefault()
    });
    s_chat.find(".s_face").tipTip({
        content: $(".smilies_div").html(),
        keepAlive: true,
        maxWidth: "242px",
        defaultPosition: "top",
        edgeOffset: -31,
        delay: 300
    });
    $(".set_busy").tipTip({content: '1. 挂起后, 将不再接受新客人加入, 但其他客服转接过来的客人仍会进入.<br><br>2. 一般地, 当自己特别忙时可使用挂起功能, 如果离开座席较长时间, 建议退出客服.<br><br>3. 如果所有在线的客服都挂起了, 挂起功能将失效.'});
    $(".sysinfo>a").tipTip({
        content: '1. 按 Ctrl + Alt: 在客服交流区与当前客人小窗口间切换.<br>2. 按 Ctrl + 下箭头 或 Esc键: 关闭当前客人小窗口.<br>3. 按 Ctrl + 上箭头: 展开关闭的客人小窗口.<br>4. 按 Ctrl + 左或右箭头: 在已展开的客人小窗口间切换.',
        maxWidth: "320px",
        defaultPosition: "top",
        delay: 300
    });
    $(".set_serving, .reset_socket").tipTip();
    pagetitle = document.title;
    $(document).mousedown(stopFlashTitle).keydown(function (e) {
        stopFlashTitle();
        if (e.which == 27 || (e.ctrlKey && e.which == 40)) {
            closeWin(CurrentId)
        } else if (e.ctrlKey && (e.which == 37 || e.which == 39)) {
            showNext()
        } else if (e.ctrlKey && e.which == 38) {
            showNext(1)
        } else if (e.ctrlKey && e.which == 18) {
            if (CurrentId) {
                if (welive.where == 1) {
                    s_msg.focus()
                } else {
                    openWin(CurrentId)
                }
            } else {
                s_msg.focus()
            }
        }
    });
    welive.sound1 = '<object data="' + SYSDIR + 'public/sound1.swf" type="application/x-shockwave-flash" width="1" height="1" style="visibility:hidden"><param name="movie" value="' + SYSDIR + 'public/sound1.swf"><param name="quality" value="high"></object>';
    welive.sound2 = '<object data="' + SYSDIR + 'public/sound2.swf" type="application/x-shockwave-flash"><param name="movie" value="' + SYSDIR + 'public/sound2.swf"></object>';
    window.onbeforeunload = function (a) {
        welive.status = 0;
        clearTimeout(welive.ttt);
        return " "
    };
    $(window).unload(function () {
        welive.status = 0;
        clearTimeout(welive.ttt)
    })
}
var tttt = 0, pagetitle, flashtitle_step = 0, sounder, towhere = 0;
var guest, offline, g_online, s_chat, s_msg, s_history, s_online, s_send, s_hwrap, s_owrap, s_admins, s_title;
var welive = {ws: {}, index: 0, status: 0, ttt: 0, flashTitle: 0, sound: 1, sound1: '', sound2: '', where: 0};
var myWin88, CurrentId = 0, zIndex = 2000;
var x_win_content = '<div class="g_history"><div class="scb_scrollbar scb_radius"><div class="scb_tracker"><div class="scb_mover scb_radius"></div></div></div><div class="viewport"><div class="overview">888888</div></div></div><div class="g_tools"><a class="t_smilies" title="表情符号"></a><a class="t_phrase" title="常用短语"></a><a class="t_transfer" title="转接客人"></a><a class="t_note" title="记录客人信息"></a><a class="t_unban" title="解除禁言" onclick="guest_unban(this);return false;"></a><a class="t_banned" title="禁止发言" onclick="guest_banned(this);return false;"></a><a class="t_kickout" title="踢出客人"></a></div><div class="g_bott"><input name="g_msg" type="text" class="g_msg"><a class="g_send" title="发送" onclick="guest_send();return false;"></a></div>';
$(function () {
    $.ajax({url: './index.php?c=opensocket&a=ajax', dataType: 'json', async: true, cache: false});
    welive_init();
    $("#topbar dl").Jdropdown({delay: 50}, function (a) {
    });
    $(".logout").click(function (e) {
        showDialog('确定退出 lyd 在线客服系统吗?', '', function () {
            document.location = 'index.php?a=logout'
        });
        e.preventDefault()
    })
});